package sys.person;

import sys.database.Database;
import sys.event.SportingEvent;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Manager {

    // OK
    public void addEvent(SportingEvent event) {
        String sql = "insert into event (eventID, eventName, place, rule) values (?, ?, ?, ?)";
        PreparedStatement preparedStatement = new Database().createConnection(sql);

        try {
            preparedStatement.setString(1, event.getId());
            preparedStatement.setString(2, event.getName());
            preparedStatement.setString(3, event.getPlace());
            preparedStatement.setString(4, event.getRule());
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            System.out.println("项目添加失败！");
        }
    }


    // OK
    public void changePlace(String eventID, String place) {
        String sql = "update event set place = ? where eventID = " + eventID;
        PreparedStatement preparedStatement = new Database().createConnection(sql);
        try {
            preparedStatement.setString(1, place);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            System.out.println("执行修改操作失败！");
        }
    }

    // OK
    public void changeRule(String eventID, String rule) {
        String sql = "update event set rule = ? where eventID = " + eventID;
        PreparedStatement preparedStatement = new Database().createConnection(sql);
        try {
            preparedStatement.setString(1, rule);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            System.out.println("执行修改操作失败！");
        }
    }
}
